using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGourd.Core.Reports;

namespace NGourd.Tests
{
    public class ReportNodeBuilder
    {
        private ReportTarget targetType; 
        private string text;
        private ReportStatus status = ReportStatus.PASSED;
        private IList<ReportNode> nodes = new List<ReportNode>();

        public ReportNodeBuilder WithTargetType(ReportTarget targetType)
        {
            this.targetType = targetType;
            return this;
        }

        public ReportNodeBuilder WithText(string text)
        {
            this.text = text;
            return this;
        }

        public ReportNodeBuilder WithStatus(ReportStatus status)
        {
            this.status = status;
            return this;
        }

        public ReportNodeBuilder WithNodes(IList<ReportNode> nodes)
        {
            this.nodes = nodes;
            return this;
        }

        public ReportNode Build()
        {
            var node = new ReportNode(targetType, text);
            node.Status = status;
            nodes.ToList().ForEach(n => node.Nodes.Add(n));
            return node;
        }

        public static ReportNode SimpleResultNodes()
        {
            var topNode = new ReportNodeBuilder().WithTargetType(ReportTarget.FEATURE).WithText("Feature1").Build();
            var firstScenario = new ReportNodeBuilder().WithTargetType(ReportTarget.SCENARIO).WithText("Scenario1").Build();
            firstScenario.Nodes.Add(new ReportNodeBuilder().WithTargetType(ReportTarget.STEP).WithText("Step1").Build());
            firstScenario.Nodes.Add(new ReportNodeBuilder().WithTargetType(ReportTarget.STEP).WithText("Step2").Build());

            var secondScenario = new ReportNodeBuilder().WithTargetType(ReportTarget.SCENARIO).WithText("Scenario2").Build();
            secondScenario.Nodes.Add(new ReportNodeBuilder().WithTargetType(ReportTarget.STEP).WithText("Step3").Build());
            secondScenario.Nodes.Add(new ReportNodeBuilder().WithTargetType(ReportTarget.STEP).WithText("Step4").Build());

            topNode.Nodes.Add(firstScenario);
            topNode.Nodes.Add(secondScenario);
            return topNode;
        }
    }
}
